<template>
	 <mdp-table  ref="tableDataListRef" currOpType="mng" operWidth="200" :params="params"  :columnCfgs="columnCfgs" :crudApis="crudApis" />
</template> 
<script> 
import {listTableData,addTableData,delTableData,batchDelTableData,editSomeFieldsTableData} from '@/api/mdp/dm/data'
import {getTableColumnList} from '@/api/mdp/dm/meta'
export default {
	name: 'TableDataList', 
	props: {
		modelValue: {
			type:[String,Array,Object],
			default:function(){
				return null
			}
		},
		dataSource:{
			type:String,
			default:'master'
		}
	},
	data(){
		return {  
			params:{
				tableName:this.modelValue,
				dataSource:this.dataSource
			},
			columnCfgs:[
				
			],
			crudApis:{
				list:listTableData,
				add: addTableData,
				del: delTableData,
				batchDel: batchDelTableData,
				editSomeFields: editSomeFieldsTableData
			}
		}
	},
	computed: {
		value:{
			set(val){
				this.$emit('update:modelValue',val)
			},
			get(){
				return this.modelValue
			}
		}
	}, 
	watch:{
		value(){
			this.initColumnCfgs();
		}
	},
	methods:{ 
		doSearch(){  
			if(!this.value){
				return;
			}
			this.columnCfgs=[]
			this.initColumnCfgs(); 
		
		},
		initColumnCfgs(){ 
			if(!this.value){
				this.$message({message:'表名不能为空',type:'error'})
				return;
			}
		 getTableColumnList({dataSource:this.dataSource,tableName:this.value}).then(res=>{
				let {data,tips}=res
				if(tips.isOk){
					this.columnCfgs=data.map(f=>{
						var col={label:f.remarks,property:this.$mdp.toCamel(f.columnName),colType:f.dataType}
						if(col.label.length>10){
							col.label=col.label.substring(0,10)
						}
						return col;
					}) 
					this.params={dataSource:this.dataSource,tableName:this.modelValue}
				}else{
					this.$message({message:tips.msg,type:'error'})
				}
			})
			
			
			//this.$refs['tableDataListRef']?.searchTableDatas(); 
		}
	},
  created(){
		 this.initColumnCfgs();
	},
	mounted() { 
	}
}
</script>
